package com.songlanyun.modules.servicegoods.controller.admin;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.servicegoods.entity.ServiceGoodsClassify;
import com.songlanyun.modules.servicegoods.model.dto.ServiceGoodsClassifyDTO;
import com.songlanyun.modules.servicegoods.service.ServiceGoodsClassifyService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 平台的服务分类
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2020-12-15 11:51:34
 */
@RestController
@RequestMapping("admin/classify")
public class ServiceGoodsClassifyAdminController extends AbstractController {
    @Autowired
    private ServiceGoodsClassifyService serviceGoodsClassifyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("servicegoods:servicegoodsclassify:list")
    public R page(@RequestParam Map<String, Object> params) {
        PageUtils page = serviceGoodsClassifyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("servicegoods:servicegoodsclassify:info")
    public R info(@PathVariable("id") Long id) {
        ServiceGoodsClassify serviceGoodsClassify = serviceGoodsClassifyService.getById(id);
        return R.ok().put("data", serviceGoodsClassify);
    }

    /**
     * 保存
     */
    @SysLog("保存平台的服务分类")
    @RequestMapping("/create")
    //@RequiresPermissions("servicegoods:servicegoodsclassify:save")
    public R create(@RequestBody ServiceGoodsClassifyDTO dto) {
        ServiceGoodsClassify data = serviceGoodsClassifyService.add(dto);
        return R.ok().put("data", data);
    }


    /**
     * 修改
     */
    @SysLog("修改平台的服务分类")
    @PutMapping("/update")
    //@RequiresPermissions("servicegoods:servicegoodsclassify:save")
    public R update(@RequestBody ServiceGoodsClassifyDTO dto) {
        ServiceGoodsClassify data = serviceGoodsClassifyService.update(dto);
        return R.ok().put("data", data);
    }


    /**
     * 删除
     */
    @SysLog("删除平台的服务分类")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("system:category:delete")
    public R delete(@PathVariable("id") Long id){
        serviceGoodsClassifyService.remove(id);
        return R.ok();
    }


    /**
     * 所有分类
     */
    @RequestMapping("/all")
    //@RequiresPermissions("system:category:all")
    public R all(){
        List<ServiceGoodsClassify> objs = serviceGoodsClassifyService.getAllCategory();
        return R.ok().put("list", objs);
    }

}
